package ar.com.tristeslos3tigres.radioapp;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.ExecutionException;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ListView;
import ar.com.tristeslos3tigres.rssfeedreader.RssFeedAdapter;
import ar.com.tristeslos3tigres.rssfeedreader.RssFeedItem;
import ar.com.tristeslos3tigres.rssfeedreader.RssFeedReaderAsync;
import ar.com.tristeslos3tigres.rssfeedreader.feedsconfiguration.BlogspotConfiguration;
import ar.com.tristeslos3tigres.rssfeedreader.feedsconfiguration.FeedConfiguration;
/*import ar.com.tristeslos3tigres.rssfeedreader.RssFeedAdapter;*/


public class ListadoNoticiasActivity extends ListActivity {
	private static final String TAG = "radioplatinofm.ListadoNoticiasActivity";

	ListView list;
	List<RssFeedItem> data;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		list = getListView();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		//getMenuInflater().inflate(R.menu.listado_noticias, menu);
		return true;
	}

	@Override
	protected void onResume() {
		super.onResume();

		ProgressDialog pdBuff = null;
		pdBuff = ProgressDialog.show(this, "Buffering...", "Acquiring song...",
				true);

		try {
			FeedConfiguration config = new BlogspotConfiguration();

			try {
				data = new RssFeedReaderAsync(config)
						.execute(
								new URL(
										"http://contactoradio.blogspot.com/feeds/posts/default"))
						.get();

				Log.v(TAG, "Cantidad de noticias recuperadas: " + data.size());
				
				list.setAdapter(new RssFeedAdapter(this, data));
				

				
				
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		pdBuff.dismiss();
	}
}